<?php
/**
 * Created by PhpStorm.
 * User: jswei
 * Date: 2018/4/24
 * Time: 8:54
 */

namespace app\admin\model;

use app\index\model\Cities;
use app\index\model\Provinces;
use think\Db;
use think\Model;

class LotteryLog extends Model{
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;
    protected $auto = ['create_time'];

    /**
     * @param array $where
     * @param int $pageSize
     * @param string $field
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($where= [], $pageSize=10,$field=''){
        $field = $field ? $field: "{$this->getTable()}.*,think_member.open_id,
        think_member.nickname,think_article.title,think_mch.name as mc_name,
        think_lottery.prize,think_lottery.money";
        $list = $this
            ->field($field)
            ->join('think_member',"think_member.id = {$this->getTable()}.mid")
            ->join('think_article',"think_article.id = {$this->getTable()}.aid")
            ->join('think_mch',"think_mch.id = {$this->getTable()}.mc_id")
            ->join('think_lottery',"think_lottery.id = {$this->getTable()}.lid")
            ->order('think_lottery_log.create_time desc')
            ->where($where)
            ->paginate($pageSize);
        return $list;
    }

    public function getUpdateTimeAttr($value){
        return $value?date('Y-m-d H:i:s',$value):'--';
    }
}